package com.zcxy.fast.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zcxy.fast.bean.PageQuery;
import com.zcxy.fast.entity.MainTable;
import com.zcxy.fast.vo.MainTableVo;
import com.zcxy.fast.service.IMainTableService;
import com.zcxy.fast.mapper.MainTableMapper;
import com.zcxy.fast.mybatisExtend.BaseServiceImpl;
import com.zcxy.fast.utils.BeanCopyUtil;
import com.zcxy.fast.utils.StringUtils;
import com.zcxy.fast.mybatisExtend.LambdaValiteCondition;
import com.zcxy.fast.mybatisExtend.RelationHelper;
import java.util.stream.Collectors;
import cn.hutool.core.collection.CollectionUtil;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;



/**
 * 主表业务层处理
 *
 * @author zcc
 * @email  860474958@qq.com
 * @date   2021-01-15 14:00:36
 */
@Service
@Slf4j
public class MainTableServiceImpl extends BaseServiceImpl<MainTableMapper, MainTable> implements IMainTableService {

    @Override
    public IPage<MainTableVo> queryPageList(PageQuery<MainTable> queryVo) {
        MainTable mainTable=queryVo.getT() == null ? new MainTable() : queryVo.getT();
        QueryWrapper queryWrapper = new QueryWrapper(mainTable);
        Page page = new Page(queryVo.getPageNo(), queryVo.getPageSize());


        IPage<MainTable> iPage = baseMapper.selectPage(page, queryWrapper);
        return BeanCopyUtil.copyPage(iPage, MainTableVo.class);
    }

    @Override
    public List<MainTableVo> queryList(MainTable mainTable) {
        MainTable mainTableq=mainTable == null ? new MainTable() : mainTable;
        QueryWrapper queryWrapper = new QueryWrapper(mainTableq);
        List<MainTableVo> MainTableVos=BeanCopyUtil.copyListToList(baseMapper.selectList(queryWrapper),MainTableVo.class);
        return MainTableVos;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addMainTable(MainTable mainTable) {
        LambdaValiteCondition<MainTable> valiteCondition = LambdaValiteCondition.newInstance(mainTable);
        baseMapper.insert(mainTable);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateMainTable(MainTable mainTable) {
        LambdaValiteCondition<MainTable> valiteCondition = LambdaValiteCondition.newInstance(mainTable);


        baseMapper.updateById(mainTable);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void removeAllMainTable(List<String> ids) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.in("id", ids);
        baseMapper.delete(queryWrapper);
    }
}
